package main

import (
	"fmt"
	"io"
	"log"
	"os"
)

type grepAlpha struct {
	ioReader io.Reader
}

func alpha(r byte) byte {
	if (r >= 'A' && r <= 'Z') || (r >= 'a' && r <= 'z') {
		return r
	}
	return 0
}

func (z *grepAlpha) Read(p []byte) (int, error) {
	n, err := z.ioReader.Read(p)
	if err != nil {
		return n, err
	}
	buf := make([]byte, n)
	for i := 0; i < n; i++ {
		if char := alpha(p[i]); char != 0 {
			buf[i] = char
		}
	}
	copy(p, buf)
	return n, nil
}

func main() {
	file, err := os.Open("/tmp/work.js")
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	defer file.Close()
	myReader := grepAlpha{
		file,
	}

	//myReader := grepAlpha{
	//	strings.NewReader("汉字lLq LWQ eee2021 ~~!"),
	//}
	p := make([]byte, 4)
	for {
		n, err := myReader.Read(p)
		if err == io.EOF {
			log.Printf("end of strings")
			break
		}
		log.Printf("print bytes:%d content:%s", n, string(p[:n]))
	}
}
